﻿using DataServices;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace LFWeb3.Controllers
{
    public class ArtWorkReviewController : Controller
    {

        DaoArtWorkReview ArtWorkReviewDao = new DaoArtWorkReview();
        int pageSize = 5;

        public ActionResult Add()
        {
            return View();
        }

        public ActionResult Update(string id)
        {
            ViewBag.ArtWorkReview = ArtWorkReviewDao.LoadArtWorkReviewById(id);
            return View();
        }

        public ActionResult Edit(int?page)
        {
            int ArtWorkReviewCount = ArtWorkReviewDao.LoadArtWorkCount();

            int curPage = page.HasValue ? page.Value : 1;
            ViewData["pager"] = new PagerInfo()
            {
                RecordCount = ArtWorkReviewCount,
                CurrentIndex = curPage,
                PageSize = pageSize
            };

            ViewData["ArtWorkReview"] = ArtWorkReviewDao.LoadArtWorkReviewByPage(curPage, pageSize); //分页数据
            return View();
        }

        public ActionResult ArtWorkReview(int? page)
        {
             //TopNews
            IList<ArtWorkReviewInfo> topReviews = ArtWorkReviewDao.LoadArtWorkReviewByPage(1, 8);
            ViewBag.topReviews = topReviews;
            int ArtWorkReviewCount = ArtWorkReviewDao.LoadArtWorkCount();

           
            int curPage = page.HasValue ? page.Value : 1;
            ViewData["pager"] = new PagerInfo()
            {
                RecordCount = ArtWorkReviewCount,
                CurrentIndex = curPage,
                PageSize = pageSize
            };

            IList<ArtWorkReviewInfo> topReview = ArtWorkReviewDao.LoadArtWorkReviewByPage(curPage, pageSize);
            ViewBag.topReview = topReview;
            return View();
        }

        public ActionResult ViewArtWorkReview(string id)
        {
            IList<ArtWorkReviewInfo> topReviews = ArtWorkReviewDao.LoadArtWorkReviewByPage(1, 8);
            ViewBag.topReviews = topReviews;
            ViewData["Review"] = ArtWorkReviewDao.LoadArtWorkReviewById(id);
            return View();
        }

        [ValidateInput(false)]
        public JsonResult AddArtWorkReview(ArtWorkReviewInfo review)
        {
            try
            {
                review.ID = Guid.NewGuid().ToString();
                ArtWorkReviewDao.AddArtWorkReview(review);
                return Json("success", JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return Json(ex.Message, JsonRequestBehavior.AllowGet);
            }
        }

        [ValidateInput(false)]
        public JsonResult UpdateArtWorkReview(ArtWorkReviewInfo review)
        {
            try
            {
                ArtWorkReviewDao.UpdateArtWorkReview(review);
                return Json("success", JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return Json(ex.Message, JsonRequestBehavior.AllowGet);
            }
        }

        [ValidateInput(false)]
        public JsonResult DeleteArtWorkReview(string id)
        {
            try
            {
                ArtWorkReviewDao.DeleteArtWorkReview(id);
                return Json("success", JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                return Json(ex.Message, JsonRequestBehavior.AllowGet);
            }
        }
    }
}
